﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        public ShopController(ShopBLL shopBLL)
        {
            ShopBLL = shopBLL;
        }

        public ShopBLL ShopBLL { get; }

        /// <summary>
        /// 增加门店
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public IActionResult ShopAdd(Shop shop)
        {
            try
            {
                int res = ShopBLL.ShopAdd(shop);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="totalPage"></param>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public IActionResult GetShops(string? name, int pageIndex, int pageSize)
        {
            try
            {
                int totalCount = 0;
                int totalPage = 0;
                List<Shop> list = ShopBLL.GetShops(out totalCount, out totalPage, name, pageIndex, pageSize);

                return Ok(new
                {
                    list = list,
                    totalCount = totalCount,
                    totalPage = totalPage
                });
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpDelete]
        public IActionResult DelShop(int id)
        {
            try
            {
                var res = ShopBLL.DelShop(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 门店信息反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public IActionResult FanShop(int id)
        {
            try
            {
                var res = ShopBLL.FanShop(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 门店修改
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public IActionResult UpdShop(Shop shop)
        {
            try
            {
                var res = ShopBLL.UpdShop(shop);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
